<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Auth;

/**
 * 用户资源
 * @package App\Http\Resources
 */
class UserResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            'name' => $this->name,
            'mobile' => $this->when($this->check(), $this->mobile)
        ] + parent::toArray($request);
    }
    protected function check()
    {
        if (Auth::check()) {
            return Auth::id() == $this->resource->id;
        }
    }
}
